package com.shigu.hotItem.action;


import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.exceptions.WapException;
import com.shigu.hotItem.api.HotItemService;
import com.shigu.hotItem.bo.*;
import com.shigu.hotItem.vo.AdminHotVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/*
 * create by  过儿  2019-06-12
 *
 */
@RequestMapping("adminjson")
@Controller
public class HotItemAdminController {

    @Resource(name = "hotItemServiceImpl")
    HotItemService hotItemService;

    @RequestMapping("addHotItem")
    @ResponseBody
    public MallResponse addHotItem(NewHotItemRequest request) throws WapException {
        HotItemBo bo = new HotItemBo();
        bo.setItemId(request.getItemId());
        bo.setImgUrl(request.getImgUrl());
        bo.setWeight(request.getWeight());
        if(StringUtils.isNotBlank(request.getCid())){
            bo.setCid(Long.valueOf(request.getCid()));
        }
        hotItemService.addHotItem(bo);
        return new MallResponse().success();
    }

    @RequestMapping("delHotItem")
    @ResponseBody
    public MallResponse delHotItem(String hotId){
        hotItemService.delHotItem(Long.valueOf(hotId));
        return new MallResponse();
    }

    @RequestMapping("hotItemList")
    @ResponseBody
    public PageResponse<AdminHotVo> hotItemList(HotItemListRequest request){
        return hotItemService.hotItemList(request.getPage(),request.getSize(),request.getCid(),request.getItemCode());
    }

    @RequestMapping("modifyHotItem")
    @ResponseBody
    public MallResponse modifyHotItem(ModHotItemRequest request){
        ModifyHotItemBo bo =  new ModifyHotItemBo();
        bo.setHotId(request.getHotId());
        bo.setCid(request.getCid());
        bo.setItemId(request.getItemId());
        if(StringUtils.isNotBlank(request.getImgUrl())){
            bo.setImgUrl(request.getImgUrl());
        }
        if(StringUtils.isNotBlank(request.getRemark())){
            bo.setRemark(request.getRemark());
        }
        bo.setWeight(request.getWeight());

        hotItemService.modifyHotItem(bo);
        return new MallResponse();
    }

}
